<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1 {width:100px; height:100px; background:red; position:absolute;}
</style>
<script>
window.onload=function ()
{
	var oDiv=document.getElementById('div1');
	
	var disX=0;
	var disY=0;
	
	oDiv.onmousedown=function (ev)
	{
		var oEvent=ev||event;
		
		disX=oEvent.clientX-oDiv.offsetLeft;
		disY=oEvent.clientY-oDiv.offsetTop;
		
		if(oDiv.setCapture)
		{
			//IE
			oDiv.onmousemove=function (ev)
			{
				var oEvent=ev||event;
				var l=oEvent.clientX-disX;
				var t=oEvent.clientY-disY;
				
				oDiv.style.left=l+'px';
				oDiv.style.top=t+'px';
			};
			
			oDiv.onmouseup=function ()
			{
				oDiv.onmousemove=null;
				oDiv.onmouseup=null;
				
				oDiv.releaseCapture();
			};
			
			oDiv.setCapture();
		}
		else
		{
			//Chrome、FF
			document.onmousemove=function (ev)
			{
				var oEvent=ev||event;
				var l=oEvent.clientX-disX;
				var t=oEvent.clientY-disY;
				
				oDiv.style.left=l+'px';
				oDiv.style.top=t+'px';
			};
			
			document.onmouseup=function ()
			{
				document.onmousemove=null;
				document.onmouseup=null;
			};
		}
		
		return false;	//chrome、ff、IE9
	};
};
</script>
</head>

<body>
asdfasdfsdf<br>
dfasfasdfasd
<div id="div1">asdfasdfsdf<br>
dfasfasdfasd</div>
asdfasdfsdf<br>
dfasfasdfasd
</body>
</html>
